<?php
class Student
{
    private $surname;
    private $first_name;
    private $emails;
    private $subject_grades = []; 
    private $status;

    function __construct($surname, $first_name, $status)
    {
        $this->surname = $surname;
        $this->first_name = $first_name;
        $this->emails = array();
        $this->status = $status;
    }

  
    function add_subject_grade($subject, $grade)
    {
     
        if (is_numeric($grade)) {
            $this->subject_grades[$subject] = $grade;
        }
    }

   
    function average()
    {
        if (empty($this->subject_grades)) return 0; 
        $total = array_sum($this->subject_grades);
        return round($total / count($this->subject_grades), 1); 
    }

    
    function toString()
    {
        $result = $this->first_name . ' ' . $this->surname;
        $result .= ' (' . $this->average() . ')  ' . $this->status . "\n";
        
        
        foreach ($this->subject_grades as $subject => $grade) {
            $result .='' . $subject . ': ' . $grade . "\n";
        }
        
        
        foreach ($this->emails as $which => $what) {
            $result .= '' . $which . ': ' . $what . "\n";
        }
        
        $result .= "\n";
        return '<pre>' . $result . '</pre>';
    }

    
    function add_email($which, $address)
    {
        $this->emails[$which] = $address;
    }

    function get_first_name()
    {
        return $this->first_name;
    }

    function get_surname()
    {
        return $this->surname;
    }

    function get_subject_grade($subject)
    {
        return $this->subject_grades[$subject] ?? 'No grade'; 
    }
}
?>